Imports PTT.CarRes.Data

Public Class ClassQueryInvDriverGroup
    Public Function Add(ByVal InvDriverGroup As QueryInvDriverGroup, ByVal StrConn As String) As Boolean
        Dim ClsInvDriverGroup As New ClassInvDriverGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvDriverGroup.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvDriverGroup
            .GroupId = InvDriverGroup.GroupId
            .GroupName = InvDriverGroup.GroupName
            .GroupDesc = InvDriverGroup.GroupDesc
            .CostDay = InvDriverGroup.CostDay
            .CostHoliday = InvDriverGroup.CostHoliday
            .OtDay = InvDriverGroup.OtDay
            .OtHoliday = InvDriverGroup.OtHoliday
            .Costnight = InvDriverGroup.Costnight
            .GroupStatus = InvDriverGroup.GroupStatus
            ret = .USP_Save(Conn)
        End With
        ClsInvDriverGroup.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Edit(ByVal InvDriverGroup As QueryInvDriverGroup, ByVal StrConn As String) As Boolean
        Dim ClsInvDriverGroup As New ClassInvDriverGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvDriverGroup.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvDriverGroup
            .GroupId = InvDriverGroup.GroupId
            .Load(Conn)
            .GroupName = InvDriverGroup.GroupName
            .GroupDesc = InvDriverGroup.GroupDesc
            .CostDay = InvDriverGroup.CostDay
            .CostHoliday = InvDriverGroup.CostHoliday
            .OtDay = InvDriverGroup.OtDay
            .OtHoliday = InvDriverGroup.OtHoliday
            .Costnight = InvDriverGroup.Costnight
            .GroupStatus = InvDriverGroup.GroupStatus
            ret = .USP_Update(Conn)
        End With
        ClsInvDriverGroup.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Delete(ByVal InvDriverGroup As QueryInvDriverGroup, ByVal StrConn As String) As Boolean
        Dim ClsInvDriverGroup As New ClassInvDriverGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvDriverGroup.ConnectionOpen(StrConn)
        Dim ret As Boolean = False
        With ClsInvDriverGroup
            .GroupId = InvDriverGroup.GroupId
            .Load(Conn)
            ret = .USP_Delete(Conn)
        End With
        ClsInvDriverGroup.ConnectionClose(Conn)
        Return ret
    End Function

    Public Function Search(Optional ByVal ParaGroupId As String = "", _
    Optional ByVal ParaGroupName As String = "", _
    Optional ByVal ParaGroupStatus As String = "", _
    Optional ByVal StrConn As String = "") As QueryInvDriverGroups
        Dim ClsInvDriverGroup As New ClassInvDriverGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvDriverGroup.ConnectionOpen(StrConn)
        Dim ret As QueryInvDriverGroups = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvDriverGroup"
        If ParaGroupId & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(GroupId = " & ParaGroupId & ")"
        End If
        If ParaGroupName & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(GroupName like '%" & ParaGroupName & "%')"
        End If
        If ParaGroupStatus & "" <> "" Then
            If Condition & "" <> "" Then
                Condition &= " and "
            End If
            Condition &= "(GroupStatus like '%" & ParaGroupStatus & "%')"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        End If
        Dim ds As DataSet
        With ClsInvDriverGroup
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvDriverGroups

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvDriverGroup( _
                              .Item("GroupId") & "", _
                              .Item("GroupName") & "", _
                              .Item("GroupDesc") & "", _
                              .Item("CostDay") & "", _
                              .Item("CostHoliday") & "", _
                              .Item("OtDay") & "", _
                              .Item("OtHoliday") & "", _
                              .Item("Costnight") & "", _
                              .Item("GroupStatus") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvDriverGroup.ConnectionClose(Conn)
        Return ret
    End Function
    Public Function Load(Optional ByVal ParaGroupId As String = "") As QueryInvDriverGroups
        Dim ClsInvDriverGroup As New ClassInvDriverGroup
        Dim Conn As OleDb.OleDbConnection
        Conn = ClsInvDriverGroup.ConnectionOpen()
        Dim ret As QueryInvDriverGroups = Nothing
        Dim str As String = ""
        Dim Condition As String = ""
        str &= " Select * from InvDriverGroup"
        If ParaGroupId & "" <> "" Then
            If Condition & "" <> "" Then Condition &= " and "
            Condition &= "(GroupId = " & ParaGroupId & ")"
        End If

        If Condition & "" <> "" Then
            str &= " where "
            str &= Condition
        Else
            Return Nothing
            Exit Function
        End If
        Dim ds As DataSet
        With ClsInvDriverGroup
            ds = .BindData(Conn, , , str)
            If Not ds Is Nothing Then
                Dim i As Integer
                Dim results As New QueryInvDriverGroups

                Try
                    For i = 0 To ds.Tables(0).Rows.Count - 1
                        With ds.Tables(0).Rows(i)

                            results.Add(New QueryInvDriverGroup( _
                              .Item("GroupId") & "", _
                              .Item("GroupName") & "", _
                              .Item("GroupDesc") & "", _
                              .Item("CostDay") & "", _
                              .Item("CostHoliday") & "", _
                              .Item("OtDay") & "", _
                              .Item("OtHoliday") & "", _
                              .Item("Costnight") & "", _
                              .Item("GroupStatus") & "" _
                            ))
                        End With
                    Next
                    ret = results
                Catch ex As Exception
                    Return Nothing
                    'Throw New DALException(ex.Message)
                End Try
            End If
        End With
        ClsInvDriverGroup.ConnectionClose(Conn)
        Return ret
    End Function
End Class